fix(ui): eliminate N+1 reactive subscriptions in SessionTurn#18924
Merged
adamdotdevin merged 2 commits intoanomalyco:devfrom Mar 24, 2026
Merged
fix(ui): eliminate N+1 reactive subscriptions in SessionTurn#18924adamdotdevin merged 2 commits intoanomalyco:devfrom
adamdotdevin merged 2 commits intoanomalyco:devfrom
Conversation
Add optional messages prop to SessionTurn so the parent MessageTimeline can pass the computed allMessages array. This replaces N store subscriptions (one per rendered turn) with a single subscription in the parent. Falls back to the existing store subscription when the prop is absent (backwards compatible with enterprise share page). Also replaces JSON.stringify equality check in the comments memo with structural field comparison.
Contributor
|
Hey! Your PR title Please update it to start with one of:
Where See CONTRIBUTING.md for details. |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Replace three independent memos (assistantVisible, assistantTailVisible, reasoningHeading) that each iterate all assistant messages and parts with a single-pass computation. One turn had 106 assistant messages / 411 parts — three memos created 3x106 store subscriptions and ~1200 part evaluations per reactive cycle.
Andres77872
pushed a commit
to Andres77872/opencode
that referenced
this pull request
Mar 26, 2026
dzianisv
pushed a commit
to dzianisv/opencode
that referenced
this pull request
Mar 26, 2026
dzianisv
pushed a commit
to dzianisv/opencode
that referenced
this pull request
Apr 2, 2026
balcsida
pushed a commit
to balcsida/opencode
that referenced
this pull request
Apr 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #18920
Type of change
What does this PR do?
Every
SessionTurninstance creates its own subscription todata.store.message[sessionID]. For N rendered turns, there are N subscriptions to the same store path. Every message update triggers ALL N memos to re-derive, cascading throughmessageIndex,message,assistantMessages,assistantVisible,assistantTailVisible, andreasoningHeading. During streaming on long sessions this freezes the browser.Adds an optional
messagesprop toSessionTurnso the parentMessageTimelinecan pass the computedallMessagesarray. This replaces N store subscriptions with a single subscription in the parent. Falls back to the existing store subscription when the prop is absent (backwards compatible with the enterprise share page).Also replaces
JSON.stringifyequality check in the comments memo with structural field comparison.How did you verify your code works?
bun testpasses forpackages/ui(5/5) andpackages/app(291/291)packages/uiChecklist